unit ServiceFilter_Tokens;
//version 0.3

interface

const
 tknFilter = 'Filter';
 //non-canonical download info
 sdiLessThan = 'lt';
 sdiGreaterThan = 'gt';
 sdiSavePath = 'savepath';
 sdiFilename = 'filename';
 sdiFileExists = 'fileexists';
 sdiNotID = 'notid';
 //filter type
 ftLessThan =     $00000001;
 ftGreaterThan =  $00000002;
 ftState =        $00000010;
 ftURL =          $00000020;
 ftResume =       $00000040;
 ftSaveTo =       $00000080;
 ftPathOnly =     $00000100;
 ftFilenameOnly = $00000200;
 ftFileExists =   $00000400;
 ftSize =         $00000800;
 ftDSize =        $00001000;
 ftSpeed =        $00002000;
 ftTime =         $00004000;
 ftTimeLeft =     $00008000;
 ftDesc =         $00010000;
 ftCategory =     $00020000;
 ftDate =         $00040000;
 ftPriority =     $00080000;
 ftNotID =        $00100000;
 ftComparisonMask = $0000000F;
 ftTypeMask =       $FFFFFFF0;

function GetFilterType(AType: Integer): Integer;
function GetFilterComparison(AType: Integer): Integer;
function GetFilterToken(AType: Integer; AText: String): String;

implementation

uses
 Tokens;

const
 //canonical info tags
 sdiState = 'state';
 sdiURL = 'url';
 sdiResume = 'resumemode';
 sdiSaveTo = 'saveto';
 sdiSize = 'size';
 sdiDownloaded = 'downloadedsize';
 sdiSpeed = 'speed';
 sdiTime = 'time';
 sdiTimeLeft = 'timeleft';
 sdiDesc = 'description';
 sdiCategory = 'categoryid';
 sdiDate = 'date';
 sdiPriority = 'priority';
 sdiMirror1 = 'mirror1';
 sdiMirror2 = 'mirror2';
 sdiMirror3 = 'mirror3';
 sdiMirror4 = 'mirror4';
 sdiMirror5 = 'mirror5';

function GetFilterType(AType: Integer): Integer;
begin
 Result:=AType and ftTypeMask;
end;

function GetFilterComparison(AType: Integer): Integer;
begin
 Result:=AType and ftComparisonMask;
end;

function GetFilterToken(AType: Integer; AText: String): String;
begin
 case GetFilterType(AType) of
  ftState: Result:=EncodeToken(sdiState, AText);
  ftURL: Result:=EncodeToken(sdiURL, AText);
  ftResume: Result:=EncodeToken(sdiResume, AText);
  ftSaveTo: Result:=EncodeToken(sdiSaveTo, AText);
  ftPathOnly: Result:=EncodeToken(sdiSavePath, AText);
  ftFilenameOnly: Result:=EncodeToken(sdiFilename, AText);
  ftFileExists: Result:=EncodeToken(sdiFileExists, AText);
  ftSize:
   begin
    case GetFilterComparison(AType) of
     ftLessThan: Result:=EncodeToken(sdiSize+sdiLessThan, AText);
     ftGreaterThan: Result:=EncodeToken(sdiSize+sdiGreaterThan, AText);
     else Result:=EncodeToken(sdiSize, AText);
     end;
   end;
  ftDSize:
   begin
    case GetFilterComparison(AType) of
     ftLessThan: Result:=EncodeToken(sdiDownloaded+sdiLessThan, AText);
     ftGreaterThan: Result:=EncodeToken(sdiDownloaded+sdiGreaterThan, AText);
     else Result:=EncodeToken(sdiDownloaded, AText);
     end;
   end;
  ftSpeed:
   begin
    case GetFilterComparison(AType) of
     ftLessThan: Result:=EncodeToken(sdiSpeed+sdiLessThan, AText);
     ftGreaterThan: Result:=EncodeToken(sdiSpeed+sdiGreaterThan, AText);
     else Result:=EncodeToken(sdiSpeed, AText);
     end;
   end;
  ftTime:
   begin
    case GetFilterComparison(AType) of
     ftLessThan: Result:=EncodeToken(sdiTime+sdiLessThan, AText);
     ftGreaterThan: Result:=EncodeToken(sdiTime+sdiGreaterThan, AText);
     else Result:=EncodeToken(sdiTime, AText);
     end;
   end;
  ftTimeLeft:
   begin
    case GetFilterComparison(AType) of
     ftLessThan: Result:=EncodeToken(sdiTimeLeft+sdiLessThan, AText);
     ftGreaterThan: Result:=EncodeToken(sdiTimeLeft+sdiGreaterThan, AText);
     else Result:=EncodeToken(sdiTimeLeft, AText);
     end;
   end;
  ftDesc: Result:=EncodeToken(sdiDesc, AText);
  ftCategory: Result:=EncodeToken(sdiCategory, AText);
  ftDate:
   begin
    case GetFilterComparison(AType) of
     ftLessThan: Result:=EncodeToken(sdiDate+sdiLessThan, AText);
     ftGreaterThan: Result:=EncodeToken(sdiDate+sdiGreaterThan, AText);
     else Result:=EncodeToken(sdiDate, AText);
     end;
   end;
  ftPriority: Result:=EncodeToken(sdiPriority, AText);
  ftNotID: Result:=EncodeToken(sdiNotID, AText);
  else Result:='';
  end;
end;

end.
